package com.woniuxy.demo.epai.controller;


import com.woniuxy.demo.epai.common.Result;
import com.woniuxy.demo.epai.controller.form.MypageForm;
import com.woniuxy.demo.epai.controller.form.ProductForm;
import com.woniuxy.demo.epai.controller.form.ProductParameterForm;
import com.woniuxy.demo.epai.model.Product;
import com.woniuxy.demo.epai.model.ProductParameter;
import com.woniuxy.demo.epai.service.IProductParameterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author epai
 * @since 2021-04-12
 */
@RestController
@RequestMapping("/epai/product-parameter")
@Slf4j
public class ProductParameterController {
    @Autowired
    private IProductParameterService service;

    /**
     * 新增商品参数表
     * @param form
     * @return
     */
    @PostMapping("/addProductParameter")
    public Result addProduct(@RequestBody ProductParameterForm form){
        log.info("进入方法,参数为,{},{}",form);
        ProductParameter productParameter = new ProductParameter();
        productParameter.setToken(form.getToken());
        productParameter.setAppearance(form.getAppearance());
        productParameter.setCId(form.getCId());
        productParameter.setCheckedOut(form.getCheckedOut());
        int line = service.addProductParameter(productParameter);
        int id = productParameter.getId();
        return Result.success(id);
    }

    @GetMapping("/getparameter")
    public Result find(int par_id){
        log.info("接收查询条件{}",par_id);
        ProductParameter productParameter = service.queryParameterById(par_id);
        return Result.success(productParameter);
    }

}

